package cz.tsystems.data;

import java.io.IOException;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.databind.JsonNode;

import android.database.SQLException;


public class DataProvider {
	
	private static DataProvider sharedDataProvider;
	
	private JsonNode logetUser;
	private JsonNode configuration;
	private JsonNode planZakazk;
	private String login;
	private String deviceID;
	private String localHostName;
	private SQLiteDBProvider theDBProvider;
	private JsonFactory jsonFactory = new JsonFactory();
	
	public JsonNode getLogetUser() {
		return logetUser;
	}
	public void setLogetUser(JsonNode logetUser) {
		this.logetUser = logetUser;
	}
	
	public JsonNode getConfiguration() {
		return configuration;
	}
	public void setConfiguration(JsonNode configuration) {
		this.configuration = configuration;
	}	
	
	public String getLogin() {
		return login;
	}
	public void setLogin(String login) {
		this.login = login;
	}	
	
	public String getDeviceID() {
		return deviceID;
	}
	public void setDeviceID(String deviceID) {
		this.deviceID = deviceID;
	}
	public String getLocalHostName() {
		return localHostName;
	}
	public void setLocalHostName(String localHostName) {
		this.localHostName = localHostName;
	}
	public static DataProvider getSharedDataProvider()
	{
		if(sharedDataProvider == null)
		{
			sharedDataProvider = new DataProvider();
			/*
	        try {
	        	Enumeration<NetworkInterface> host = java.net.NetworkInterface.getNetworkInterfaces();
//	        	Log.d("HOSTNAME", host.toString());
	        	String hostName = null;
	        	NetworkInterface ni = java.net.NetworkInterface.getByName("wlan0");
	        	for (Enumeration<InetAddress> enumIpAddr = ni.getInetAddresses(); enumIpAddr.hasMoreElements();) {
	                InetAddress inetAddress = enumIpAddr.nextElement();
	                     if (!inetAddress.isLoopbackAddress()) {
	                    	 hostName =  inetAddress.getHostAddress().toString();
	                     }
	                }	        	
//	        	hostName = ni.getDisplayName();//java.net.InetAddress.getByName("wlan0").getHostName();
	        	Log.d("HOSTNAME", hostName);	        	
//				sharedDataProvider.setLocalHostName(java.net.InetAddress.getByName(host.toString()));
			} catch (Exception e) {
				e.printStackTrace();
			}
	        Log.i("JSON before sending", sharedDataProvider.getLocalHostName());
	        */
		}
		return sharedDataProvider;
	}
	public SQLiteDBProvider getTheDBProvider() {
		return theDBProvider;
	}
	public void setTheDBProvider(SQLiteDBProvider theDBProvider) {
		this.theDBProvider = theDBProvider;
		
		try {

			theDBProvider.createDataBase();

		} catch (IOException ioe) {

			throw new Error("Unable to create database");

		}

		try {

			theDBProvider.openDataBase();

		} catch (SQLException sqle) {

			throw sqle;

		}		
	}
	public JsonFactory getJsonFactory() {
		return jsonFactory;
	}
	public JsonNode getPlanZakazk() {
		return planZakazk;
	}
	public void setPlanZakazk(JsonNode planZakazk) {
		this.planZakazk = planZakazk;
	}
}
